import cv2
import numpy
import os

dirPath = '/home/ian/Documents/number_sample/'
DataFile = open('Data/Number', 'w')
for num in range(1, 8):
    numSetPath = dirPath + str(num) + '/'
    filenum = 0
    for lists in os.listdir(numSetPath):
        sub_path = os.path.join(numSetPath, lists)
        if os.path.isfile(sub_path):
            filenum = filenum+1
    for i in range(0, filenum - 10): 
        writeContent = ''
        filePath = numSetPath + str(i) + '.jpg'
        tempData = cv2.imread(filePath)
        tempData = cv2.cvtColor(tempData, cv2.COLOR_BGR2GRAY)
        tempData = cv2.resize(tempData, (20, 30), interpolation=cv2.INTER_CUBIC)
        cv2.imshow('s', tempData)
        cv2.waitKey(1)
        tempData = tempData.reshape(1, 600)
        writeContent += str(num) + ' '
        for k in range(0, 600):
            pointData = 1
            if tempData.item(0, k) < 100:
                pointData = 0
            writeContent += str(k+1) + ':' + str(pointData) + ' '
        writeContent += '\n'
        DataFile.write(writeContent)
            # cv2.imshow('s', tempData)
            # cv2.waitKey(1)
